package com.iemes.controller.warehouse;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.AnalyzeformFormMap;
import com.iemes.entity.ProductreturnFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.warehouse.AnalyzeformMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/negativeproduct_form/")
@Controller
public class Negativeproduct_FormController extends BaseController {

	@Inject
	private AnalyzeformMapper analyzeformMapper;

	// 查看负库存产品信息表，显示按钮。
	@RequestMapping("negativeproduct_form")
	public String negativeproduct_form(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/negativeproduct_form_list";
	}

	// 负库存产品信息表分页
	@ResponseBody
	@RequestMapping("negativeproduct_form_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		AnalyzeformFormMap analyzeformFormMap = getFormMap(AnalyzeformFormMap.class);
		List<Map<String, Object>> analyze=analyzeformMapper.getAllNegative(analyzeformFormMap);
		LuogicPaging(pageNow, pageSize, analyze);
		return pageView;
	}

	// 编辑负库存产品信息表
	@RequestMapping("negativeproduct_form_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id获得负库存产品信息表
			AnalyzeformFormMap negative=analyzeformMapper.getById(id);
			model.addAttribute("negative",negative);
		}
		return Common.BACKGROUND_PATH + "/warehouse/negativeproduct_form_edit";
	}

	// 修改负库存产品信息表
	@ResponseBody
	@RequestMapping(value = "negativeproduct_form_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module = "负库存产品信息表", methods = "查看负库存产品信息表-修改负库存产品信息表") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity(HttpServletRequest request) throws Exception {
		AnalyzeformFormMap analyzeformFormMap = getFormMap(AnalyzeformFormMap.class);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		// 获取request
		request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  
		// 通过工具类获取当前登录的bean
		UserFormMap userFormMap = (UserFormMap)Common.findUserSession(request);
		analyzeformFormMap.put("negativeTime", sdf.format(date));
		analyzeformFormMap.put("negativePeopleId", userFormMap.getInt("id"));
		baseMapper.editEntity(analyzeformFormMap);
		return "success";
	}	
}








